// 点击全选或者取消全选
// console.log($("#allCheck"));
// var bool = false;
// $("#allCheck").click(function() {
//     // 获取到当前的 复选窗口
//     // console.log($(this).parent().parent().eq(0).children().eq(0));
//     var checked = $("#select-all").is(":checked");
//     console.log(checked);
//     $(".td_1").children().attr("checked", checked);
// })

// let arr = []
//     // 取出sessionStorage数据
// let ss = sessionStorage;
// let a = JSON.stringify(ss) //转为字符串
// let b = JSON.parse(a) //转为json对象

// let obj = ss.parseJSON();
// let a = arr.push(ss)
// console.log(a);
// console.log(arr.push(b));
// console.log(b.id);
// arr.push(b)
// console.log(arr);
// for (index in ss) {
//     console.log(ss.getItem(index));
// }

// for (var i = 0; i < ss.length; i++) {
//     var name = ss.image;
//     var title = ss.getItem("title")
//     console.log(name, title);

// }


// console.log(ss.getItem("image"))
// console.log(ss.getItem("title"))
// console.log(ss.getItem("edition"))
// console.log(ss.getItem("color"))
// console.log(ss.getItem("buy"))
// console.log(ss.getItem("num"))
// console.log(ss.getItem("id"))




// window.onload = function() {
let ss = sessionStorage;
ss.removeItem("IsThisFirstTime_Log_From_LiveServer")
    // ss.setItem(id, [ediData, colData, buyData, num, imAge, title, id, idNum])
let a = JSON.stringify(ss) //转为字符串
let b = JSON.parse(a) //转为json对象
let arr = []
$("tbody").empty()
for (index in b) {
    // console.log(b[index]);
    // console.log(b[index].split(",")[4]);
    let node = `
        <tr>
            <td class=" t-l " style="width:188 px; ">
                <input type="checkbox " id="select-0 " checked name="sex " style="display: none; ">
                <label for="select-0 " class="checkboxCol active ">
                <div class="icon-select-col "">
                    <i class="icon-select animate-common "></i>
                </div>
                <span></span>
                </label>
            </td>
                <td style="width: 70px; ">
                <div class="img-col ">
                    <img src="${b[index].split(",")[4]}" alt=" " style="width:70px;height:70px">
                </div>
            </td>
            <td style="width: 246px; ">
                <!-- <p class="pro-name ">腾讯黑鲨游戏手机3S</p> -->
                <p class="pro-desc ">${b[index].split(",")[5]}</p>
            </td>
            <td style="width: 134px; ">
                <div class="sel-num ">
                    <button class="reduce-num " id="reduce0">-</button>
                    <i class="num ">${b[index].split(",")[6]}</i>
                    <button class="add-num " id="add0">+</button>
                </div>
            </td>
            <td style="width: 134px; ">${b[index].split(",")[8]}</td>
            <td style="width: 134px; ">待付款</td>
            <td style="width: 134px; " class="del">
                <i class="fa fa-trash-o iconfont icon-lajixiang"></i>
            </td>
        </tr>`
    $(node).appendTo($("tbody"))

}
totalPrice()





// 计算商品合计
function totalPrice() {
    let $tr = $("tbody").find("tr")
    let sum = 0;
    $tr.each(function(i, dom) {
        let num = $(dom).children("td").eq(3).find("i").text() //商品数量
        var price = num * $(dom).children("td").eq(4).text().split("￥")[1]; //商品小计
        sum += price
    });
    $(".total-price").html(sum)
}
// totalPrice()


// 商品增加减少计算
function changeNum(dom, flag) {
    var $input = $(dom).parent().find("i")
    var value = Number($input.text())
        // console.log(value);
    if (flag) {
        value--;
        if (value < 0) {
            value = 0
        }
    } else {
        value++;
    }
    $input.html(value)
    totalPrice()
}
// 减少
$(".reduce-num").click(function() {
        changeNum(this, true)
    })
    // 增加
$(".add-num").click(function() {
    changeNum(this, false)
})

// 点击删除
$(".del").find("i").click(function() {
    // console.log();
    console.log($(this));
    $(this).parent().parent().remove()
    totalPrice()
})